<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>头像设置</title>
    <link rel="stylesheet" th:href="@{/Ui/layui-v2.6.4/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/Ui/bootstrap/css/bootstrap.css}">
</head>
<body style="background-color: #e1e1e1">
<div style="margin-left: 25px;width: 100%;text-align: center">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>请点击进行头像上传</legend>
    </fieldset>
    <div class="layui-upload">
        <button type="button" class="layui-btn" id="test1">上传图片</button>
        <div class="layui-upload-list">
            <img class="layui-upload-img" id="demo1" style="width: 200px;height: 260px;">
            <p id="demoText"></p>
        </div>
        <div style="width: 200px;margin: 0 auto" >
            <div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="demo">
                <div class="layui-progress-bar" lay-percent=""></div>
            </div>
        </div>
    </div>
</div>




<script th:src="@{/Ui/layui-v2.6.4/layui/layui.js}"></script>
<script th:src="@{/Ui/bootstrap/js/bootstrap.js}"></script>

<script>
    layui.use(['upload', 'element'], function(){
        var $ = layui.jquery
            ,upload = layui.upload
            ,element = layui.element;

        //常规使用 - 普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: 'updateHead' //改成您自己的上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });

                element.progress('demo', '0%'); //进度条复位
                layer.msg('上传中', {icon: 16, time: 0});
            }
            //进度条
            ,progress: function(n, index, e){
                element.progress('demo', n + '%'); //可配合 layui 进度条元素使用
                if(n == 100){
                    layer.msg('上传完毕', {icon: 1});
                }
            }
        });
    });
</script>
</body>
</html>